 #include <iostream>
#include <string>
#include <vector>

int main() {
    std::string p;
    std::getline(std::cin, p);

    std::vector<std::string> a;
    std::string word;
    for (char c : p) {
        if (c == ' ') {
            a.push_back(word);
            word = "";
        } else {
            word += c;
        }
    }
    a.push_back(word);

    std::string num = "";
    bool flag = true;
    for (const std::string& i : a) {
        if (i == "zero") {
            num += '0';
        } else if (i == "one") {
            num += '1';
        } else if (i == "two") {
            num += '2';
        } else if (i == "three") {
            num += '3';
        } else if (i == "four") {
            num += '4';
        } else if (i == "five") {
            num += '5';
        } else if (i == "six") {
            num += '6';
        } else if (i == "seven") {
            num += '7';
        } else if (i == "eight") {
            num += '8';
        } else if (i == "nine") {
            num += '9';
        }
    }

    if (num.length() != 3) {
        flag = false;
        std::cout << "Wrong input" << std::endl;
    }

    if (flag) {
        int ot = 0;
        for (int j = 1; j < std::stoi(num); ++j) {
            for (int x = 2; x < j; ++x) {
                if (j % x == 0) {
                    break;
                }
                if (x == j - 1) {
                    ot = j;
                }
            }
        }

        for (int j = std::stoi(num); j < std::stoi(num) + std::stoi(num) - ot; ++j) {
            for (int x = 2; x < j; ++x) {
                if (j % x == 0) {
                    break;
                }
                if (x == j - 1) {
                    ot = j;
                }
            }
        }

        std::cout << ot << std::endl;
    }

    return 0;
}
